<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>observe()方法</title>
</head>
<body>
  <script>
    const observer = new MutationObserver(() => console.log('<body> attributes changed'));

    observer.observe(document.body, { attributes: true });
    // 执行以上代码，<body> 元素上任何属性发送变化都会被这个 MutationObserver 实例发现

    document.body.className = 'foo';

    console.log('Changed body class');

    // Changed body class
    // <body> attributes changed
  </script>
</body>
</html>